﻿using System;
using System.Collections.Generic;
using MvvmFx.Common.ExtensionMethods;

namespace MvvmFx.Common.ViewModels
{
    public partial class ViewModelCollection<T>
    {
        /// <summary>
        /// Add a range of items where the predicate matches the items
        /// </summary>
        /// <param name="items"></param>
        /// <param name="match"></param>
        public void AddRange(ViewModelCollection<T> items, Predicate<T> match)
        {
            List<T> filter = new List<T>(items);
            filter = filter.FindAll(match);
            filter.ForEach(item => this.Add(item));
        }

        /// <summary>
        /// Remove a range of items where the predicate matches the items
        /// </summary>
        /// <param key="items"></param>
        /// <param key="match"></param>
        public void RemoveAll(Predicate<T> match)
        {
            var matchedItems = new List<T>(this).FindAll(match);
            RemoveAll(matchedItems);
        }
    }
}
